import os
import util.doc as doc
import util.zip as zipfile
import docx2pdf
import argparse
from rich.progress import track

# 示例调用
folder_path = './products'  # 要打包的文件夹路径
output_path = './products.zip'  # 打包后的输出路径


#遍历产品文档，将doc先转化为pdf再将pdf文件转化为图片,并且将所得到的图片依次上传至云,组成所需要的pdf 优点格式固定
rootPath = os.path.dirname('./products/')
if __name__ == '__main__':
    products = os.listdir(rootPath)
    for product in track(products,description="word to pdf"):
        files = os.listdir(rootPath+'/'+product)
        for file in files:
           fileNamePath = rootPath+'/'+product+'/'+file
           fileNames =os.listdir(fileNamePath)
           for fileName in fileNames:
               filePath= rootPath+'/'+product+'/'+file+'/'+fileName
               if filePath.endswith('.docx'):
                   docx2pdf.convert(filePath, rootPath+'/'+product+'/'+file+'/'+fileName.replace('.docx','.pdf'))
    for product in track(products,description="pdf to png"):
        files = os.listdir(rootPath+'/'+product)
        for file in files:
           fileNamePath = rootPath+'/'+product+'/'+file
           fileNames =os.listdir(fileNamePath)
           for fileName in fileNames:
               filePath= rootPath+'/'+product+'/'+file+'/'+fileName
               if filePath.endswith('.pdf'):
                    doc.gengerateHtml(doc.pdfToPng(filePath))

zipfile.zip_folder(folder_path,output_path)